{extend name="mainadmin@layouts/base" /}
{block name="head" }
<link href="__STATIC__/main/css/stylesheets/uploadify/uploadify.min.css" rel="stylesheet"/>
<link href="__STATIC__/main/css/stylesheets/page/goods.css?v=1" rel="stylesheet"/>
{/block}
{block name="main" }

<header>
    <div class="page-breadcrumbs">
        <ul class="breadcrumb">
            <li>
                <i class="fa fa-ellipsis-v"></i>
                <strong>{$row['id'] ? '编辑评论' : '添加评论'}</strong>
            </li>
        </ul>

        <a class="pull-right pointer p-r" data-toggle="back" title="返回"><i class="fa fa-reply"></i></a>
    </div>
</header>

<section class="scrollable wrapper">
    <form class="form-horizontal form-validate" method="post" action="">
        {if condition="$row.id > 0"}
         <div class="form-group">
            <label class="col-sm-2 control-label">评论商品/分类：</label>
            <div class="col-sm-4 m-t-md">
              {$row.by_name} 
            </div>
        </div> 
        {else/}
         <div class="form-group">
            <label class="col-sm-2 control-label">评论类型</label>
            <div class="col-sm-4 ">
               <label><input name="type" type="radio" class="type_radio" value="goods" {$row['type']=='goods'?'checked':''} /> 商品</label>
               <label><input name="type" type="radio" class="type_radio"  value="goods_category" {$row['type']=='goods_category'?'checked':''}/> 分类</label>
            </div>
        </div>        
        <div class="form-group cat_div {$row['type']=='goods'?'hide':''}">
            <label class="col-sm-2 control-label">商品分类</label>
            <div class="col-sm-3 must">
                <select name="cat_id" id="sel_category" style="width:100%;" >
                    <option value="">请选择商品分类</option>
                    {$categoryOpt|raw}
                </select>
            </div>
        </div>
        <div class="form-group goods_div {$row['type']=='goods'?'':'hide'}">
              <label class="col-sm-2 control-label">指定商品：</label>
              <div class="col-sm-4 " >
                  <input type="text" class="input-small"  id="goods_keyword" placeholder="商品名称/SN"  value="" style="width:120px;" /> <a href="javascript:;" class="m-xs" title="查看"  onclick="searchgoods('goods_keyword','select_goods');"><i class="fa fa-search text-muted"></i></a>
                  <select id="select_goods"  style="width: 200px; " >
                      <option value="">选择商品</option>
                  </select>               
              </div>
              <div class="clearfix"></div>
              <label class="col-sm-2 control-label">指定商品：</label>
              <div class="col-sm-8 m-t-md" id="goods_name">{$row['goods_name']?$row['goods_name']:'-----请选择商品-----'}</div>
              <input name="goods_id" id="goods_id" type="hidden" value="0" />
        </div>
		<input name="by_name" id="by_name" type="hidden" value="" />
        {/if}
       {if condition="$row.user_id > 0"}
       <div class="form-group">
                <label class="col-sm-2 control-label">评论会员：</label>               
                <div class="col-sm-4 "> 
                	{$row.user_id|userInfo} 
                     <a href="{:url('member/sys_admin.users/info',['user_id'=>$row['user_id']])}" class="m-xs" title="查看会员"  ><i class="fa fa-search text-muted"></i></a>           
                </div>
        </div>
       {else/}
        <div class="form-group">
        	<label class="col-sm-2 control-label">虚拟会员：</label>
         	<select id="avatar_user"  style="width: 200px; " >
                <option value="0">随机分配虚拟会员</option>
            </select>    
            <a href="javascript:;" class="m-xs" title="查看"  onclick="searchAvatarUser();"><i class="fa fa-refresh text-muted"></i></a>           
        </div>
       {/if}

        <div class="line line-dashed line-lg pull-in"></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">评论内容：</label>
            <div class="col-sm-4 must">
                <textarea class="input-max" name="content" style="width:100%; height:100px;" data-rule-maxlength="500" data-rule-required="true">{$row.content}</textarea>
            </div>
        </div>
		<div class="form-group">
            <label class="col-sm-2 control-label">评论图片：</label>
            <div class="col-sm-10">
        <div class="js_upload_container">
            <div class="js_file_upload ">
                <button type="button" class="btn btn-default js_new_upload" data-submitname="GoodsImages" data-count="20" data-uploadpath="{:url('uploadImg')}"  data-delpath="{:url('removeImg')}" data-data="{ 'comment_id':'{$row.id|intval}' }" style="position: relative; z-index: 1;">上传图片</button>
                <span class="maroon">*</span>
                <span class="help-inline">(<small>可拖拽图片调整显示顺序 </small>)</span>
            </div>
            <div class="uploadify-queue js_file_upload_queue">
            </div>
             <ul class="ipost-list ui-sortable js_fileList" data-required="true">
{volist name="imgs" id="gg"  }
<li class="imgbox" data-post-id="{$gg.img_id}" data-path="{$gg.goods_img}">
<a class="item_new_close item_close" href="javascript:void(0)" data-delpath="{:url('removeImg')}"  title="删除"  data-post-id="{$gg.id}"></a>  
<input value="{$gg.id}" name="GoodsImages[id][]" type="hidden"> 
<span class="item_box"><img src="{$gg.thumbnail}"></span>
</li>
{/volist}                                           
             </ul>
        </div>
    </div>
     
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">状态：</label>
            <div class="col-sm-4 ">
               <label><input name="status" type="radio"  value="1" {$row['status']=='1'?'checked':''} /> 待审核</label>
               <label><input name="status" type="radio"  value="2" {$row['status']=='2'?'checked':''}/> 显示</label>
               <label><input name="status" type="radio"  value="3" {$row['status']=='3'?'checked':''}/> 隐藏（前台不显示）</label>
            </div>
        </div> 
        <div class="line line-dashed line-lg pull-in" style="width:99%;"></div>
        <div class="form-group" style="width:90%;">
            <div class="col-sm-4 col-sm-offset-2"><input name="id" type="hidden" value="{$row['id']}" />
                <button type="submit" class="btn btn-primary js_save_submit" data-loading-text="保存中...">保存</button>
                <button type="button" class="btn btn-default" data-toggle="back">取消</button>
            </div>
        </div>

    </form>
</section>

{/block}

{block name="footer" }
<script type="text/javascript">
    seajs.use(["dist/plupload/init.js"]);
	$('.type_radio').click(function(){
		if ($(this).val() == 'goods'){
			$('.cat_div').addClass('hide');
			$('.goods_div').removeClass('hide');
		}else{
			$('.goods_div').addClass('hide');
			$('.cat_div').removeClass('hide');
		}
	})
	$('#select_goods').change(function(){
		$('#goods_name').html($(this).val()+' - '+$(this).find("option:selected").text())
		$('#goods_id').val($(this).val());
		$('#by_name').val($(this).find("option:selected").data('goods_name'));
	})
	$('#sel_category').change(function(){
		$('#by_name').val($(this).find("option:selected").data('text'));
	})
	//随机获取虚拟会员
	function searchAvatarUser() {
		$("#avatar_user option").each(function(){if ($(this).val() != 0) $(this).remove();});	
		var res = jq_ajax("{:url('shop/sys_admin.AvatarUser/pubSearch')}");	
		if (res.msg)  _alert(res.msg);
		if (res.code == 0) return false	
		var arr = res.list;
		$.each(res.list,function(i,val){
			$("#avatar_user").append("<option value='"+val.id+"' data-headimgurl='"+val.headimgurl+"'>"+val.user_name+"</option>"); 
		}); 
		   
	}
	searchAvatarUser();
</script>
{/block}